package com.guigu.systemservice.controller;


import com.guigu.commonutils.R;
import com.guigu.commonutils.ResponseUtil;
import com.guigu.servicebase.exceptionhandler.MyCustomeException;
import com.guigu.systemservice.entity.SysOperation;
import com.guigu.systemservice.service.SysOperationService;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * <p>
 * 页面操作按钮 前端控制器
 * </p>
 *
 * @author Jane
 * @since 2024-09-06
 */
@CrossOrigin
@RestController
@RequestMapping("/systemservice/sys-operation")
public class SysOperationController {

    @Autowired
    private SysOperationService sysOperationService;

    @GetMapping("/list")
    public R list() {
        int count = 0;
        if(count <= 0)
            throw new MyCustomeException(20002, "库存必须大于0");

        List<SysOperation> sysOperationList = sysOperationService.list(null);
        return R.ok().data("sysOperationList", sysOperationList);
    }


    @GetMapping("/testOut")
    public void testOut(HttpServletResponse response) throws IOException {
        R r = R.ok();
        Student student = new Student();
        student.setId(1);
        student.setName("aaa");
        r.data("k1", student);
        ResponseUtil.out(response, r);
    }
}

@Data
class Student{
    private int id;
    private String name;
}

